package aop.common.advice;

import org.aspectj.lang.JoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import aop.common.model.dao.SearchKeywordCountDAO;

@Repository
public class SearchKeywordCountAspect {
	
	@Autowired
	private SearchKeywordCountDAO dao;
	
	//학교/학생 조회시 keyword가 있으면 그 키워드를 SEARCH_COUNT 테이블에 저장처리
	public void keywordCount(JoinPoint point){
		/*
		이미 저장된 keyword이면 count값을 +1 하도록 update
		저장 안된 keyword이면count값은 1로 새로 insert
		*/
		Object param = point.getArgs()[0];
		System.out.println(param);
		if(dao.selectCountKeyword(param)==0){
			dao.insertSearchKeyword(param);
		}else{
			dao.updateSearchKeyword(param);
		}
	}
}
